package com.zhuss.job.processor;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.job.job.CreateJobAppendBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.core.processor.UserRead;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.util.JsonUtil;
import com.zhuss.job.db.dao.ext.JobAppendDao;
import com.zhuss.job.db.entity.JobAppend;

/**
 * 创建职位Append processor
 * @Author: zhushanshuo
 * @Date: 2019/9/24 19:54
 */
@Component("jobAppendCreate")
public class JobAppendCreate extends AbstractProcessor<Object, CreateJobAppendBo> implements Processor<Object, CreateJobAppendBo> {

    @Autowired
    private JobAppendDao jobAppendDao;
    
    @Autowired
    @Qualifier("userRead")
    private UserRead userRead;
    
    
    /**
     * 校验
     */
    @Override
    public void check(CreateJobAppendBo bo) throws WpsException {
    	
    }
    
    /**
     * 操作方法
     * @throws WpsException 
     */
    @Override
    public Object process(CreateJobAppendBo param) throws WpsException {
    	JobAppend record = new JobAppend();
    	record.setJobId(param.getJobId());
    	record.setType(param.getType());
    	record.setTitle(param.getTitle());
    	record.setCompany(param.getCompany());
    	record.setStation(param.getStation());
    	record.setTreatment(param.getTreatment());
    	record.setAddress(param.getAddress());
    	record.setPhone(param.getPhone());
    	record.setSort(param.getSort());
    	record.setWx(param.getWx());
    	record.setBlog(param.getBlog());
    	record.setQq(param.getQq());
    	record.setIntroduction(param.getIntroduction());
    	
    	record.setCreatorUrl(userRead.picUrl(param.getConcurrentUserId()));
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	jobAppendDao.create(record);
    	param.setTargetId(record.getJobAppendId());
        return null;
    }
    
    /**
     * 操作日志
     */
	@Override
	public Object log(CreateJobAppendBo param) throws WpsException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.职位.key());
    	record.setAction(LogActionEnum.职位Append创建.key());
    	record.setTargetId(param.getTargetId());
    	record.setTargetName(param.getTitle());
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}
}
